package InformationManagement;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class TeacherTableModel extends AbstractTableModel{
	private List<Teachers> list = new ArrayList<>();
	@Override
	public int getRowCount() {
		
		return list.size();
	}

	@Override
	public int getColumnCount() {
		return 5;
	}
	  @Override
	  public String getColumnName(int column) {
	    //根据实际情况返回列名
	    if (column == 0)
	      return "ID";
	    else if (column == 1)
	      return "姓名";
	    else if (column == 2)
		      return "性别";
	    else if (column == 3)
		      return "年龄";
	    else if (column == 4)
		      return "班级";
	    return "未获取到数值";
	  }

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Teachers student = list.get(rowIndex);
		 if (columnIndex == 0)
		      return student.getId();
		    else if (columnIndex == 1)
		      return student.getName();
		    else if (columnIndex == 2)
			      return student.getSex();
		    else if (columnIndex == 3)
			      return student.getAge();
		    else if (columnIndex == 4)
			      return student.getClassname();
		return student.getName();
	}
	public void setData(List<Teachers> list) {
	    if (list == null)
	      throw new IllegalArgumentException("参数list不能为null。");
	 
	    this.list = list;
	    
	    fireTableDataChanged();//通知所有侦听器表的结构已经更改。
	  }

}
